﻿(function () {
    var app = angular.module("myapp", []);
    app.controller("HomeController", function ($scope, $http) {
        $scope.model = {};
        $scope.showAddButton = false;
        $scope.showSpan = true;
        $scope.GetProducts = function () {
            $http.get('/Home/IndexVM').success(function (data) {
                $scope.model = data;

            });
        }
        $scope.GetProducts();



        $scope.showHideButton = function (IsShow) {
            $scope.showAddButton = IsShow;
        }
        $scope.new={
            Product:{}
        };
        $scope.SaveProduct = function () {
            $http.post('/Home/SaveProduct', $scope.new.Product).success(function (data) {
                $scope.model.push(data);
                $scope.showAddButton = false;
                $scope.new.Product = {};
            });
            
        }

        $scope.showEditableField = function (IsShow) {
            $scope.showSpan = IsShow;
        }
        $scope.UpdateProduct = function (product) {
            $scope.showSpan
            $http.post('/Home/UpdateProduct', product).success(function (data) {
                $scope.showSpan = true;
                $scope.GetProducts();
            });

        }
        $scope.DeleteProduct = function (productID) {
            $http.post('/Home/DeleteProduct', { productID: productID }).success(function (data) {
                $scope.GetProducts();
            });

        }
    });
})();
